{% extends "base.html" %}
{% load display static %}

{% block title %}Minijack: Live of a Device{% endblock %}

{% block javascripts %}
  <script type="text/javascript" language="javascript"
      src="{% static 'js/device_life.js' %}"></script>
  <script type="text/javascript" language="javascript">
    var aaEvents = {{ grouped_event|Jsonify }}
  </script>
{% endblock %}

{% block body %}
  <h1>Minijack: Life of a Device</h1>

  <div class="container">
    <div class="right">
      <h2>Component Information</h2>
      <table class="screen">
        <tbody>{% for comp in comps %}
          <tr>
            <th align="left">{{ comp.component_class }}</th>
            <td>{{ comp.component_name }}</td>
          </tr>{% endfor %}
        </tbody>
      </table>
     </div>

     <div class="left">
     <h2>Device Information</h2>
      <table class="screen">
        <tbody>
          <tr>
            <th align="right">device_id</th>
            <td>{{ device.device_id }}</td>
          </tr>
          <tr>
            <th align="right">goofy_init_time</th>
            <td>{{ device.goofy_init_time }}</td>
          </tr>
          <tr>
            <th align="right">serial</th>
            <td>{{ device.serial }}</td>
          </tr>
          <tr>
            <th align="right">mlb_serial</th>
            <td>{{ device.mlb_serial }}</td>
          </tr>
          <tr>
            <th align="right">hwid</th>
            <td>{{ device.hwid }}</td>
          </tr>
          <tr>
            <th align="right">ips</th>
            <td>{{ device.ips }}</td>
          </tr>
          <tr>
            <th align="right">ips_time</th>
            <td>{{ device.ips_time }}</td>
          </tr>
          <tr>
            <th align="right">mj_status</th>
            <td>{{ device.minijack_status }}</td>
          </tr>
        </tbody>
      </table>

      <h2>Test Statistic</h2>
      <table class="screen">
        <tbody>
          <tr>
            <th align="right">PASSED</th>
            <th colspan="2"></th>
            <th>FAILED</th>
          </tr>
          <tr>
            <td align="right">{{ stat.cpassed }}</td>
            <td bgcolor="green"
                width="{% widthratio stat.cpassed stat.ctotal 200 %}"/></td>
            <td bgcolor="red"
                width="{% widthratio stat.cfailed stat.ctotal 200 %}"/></td>
            <td>{{ stat.cfailed }}</td>
          </tr>
        </tbody>
      </table>
      <p></p>
      <table class="screen">
        <tbody>
          <tr>
             <th>Top Failed</th>
             <th>Count</th>
          </tr>{% for test in stat.top_failed %}
          <tr>
            <td>{{ test.path }}</th>
            <td align="right">{{ test.count }}</td>
          </tr>{% endfor %}
        </tbody>
      </table>
    </div>
  </div>

  <h2>Test Information</h2>
  <table id="test_table">
    <thead>
      <tr>
        <th></th>
        <th>event_id</th>
        <th>event_seq</th>
        <th>invocation</th>
        <th>status</th>
        <th>path</th>
        <th>pytest_name</th>
        <th>start_time</th>
        <th>end_time</th>
        <th>duration</th>
        <th>factory_md5sum</th>
        <th>reimage_id</th>
        <th>error_msg</th>
      </tr>
    </thead>
    <tfoot>
      <tr>
        <th></th>
        <th>event_id</th>
        <th>event_seq</th>
        <th>invocation</th>
        <th>status</th>
        <th>path</th>
        <th>pytest_name</th>
        <th>start_time</th>
        <th>end_time</th>
        <th>duration</th>
        <th>factory_md5sum</th>
        <th>reimage_id</th>
        <th>error_msg</th>
      </tr>
    </tfoot>
    <tbody>{% for test in tests %}
      <tr>
        <td width="20">{% if test.invocation in grouped_event %}
          <img src="{% static 'images/details_open.png' %}"/>{% endif %}
        </td>
        <td align="center">
          <a href="{% url 'event' test.event_id %}" class="datatable_link">
            {{ test.event_id|slice:":5" }}...{{ test.event_id|slice:"-5:" }}
          </a>
        </td>
        <td align="right">{{ test.event_seq }}</td>
        <td>{{ test.invocation }}</td>
        <td>{{ test.status }}</td>
        <td>{{ test.path }}</td>
        <td>{{ test.pytest_name }}</td>
        <td>{{ test.start_time|slice:"5:19" }}</td>
        <td>{{ test.end_time|slice:"5:19" }}</td>
        <td align="right">{{ test.duration|floatformat:3 }}</td>
        <td>{{ test.factory_md5sum|truncatechars:18 }}</td>
        <td>{{ test.reimage_id|truncatechars:18 }}</td>
        <td>{{ test.error_msg|truncatechars:200 }}</td>
      </tr>{% endfor %}
    </tbody>
  </table>
{% endblock %}
